package com.lyf.controller.user;

import com.lyf.dto.ShoppingCartDTO;
import com.lyf.pojo.ShoppingCart;
import com.lyf.result.Result;
import com.lyf.service.user.ShoppingCartService;
import com.lyf.vo.ShopVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "用户端购物车接口")
@RestController
@RequestMapping("/user/shoppingCart")
public class shoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @ApiOperation("添加购物车")
    @PostMapping("add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO)
    {
        log.info("添加购物车：{}", shoppingCartDTO);
        shoppingCartService.add(shoppingCartDTO);
        return Result.success();
    }
    @ApiOperation("删除购物车中的商品")
    @PostMapping("sub")
    public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("删除购物车中的商品：{}", shoppingCartDTO);
        shoppingCartService.sub(shoppingCartDTO);
        return Result.success();
    }

    @ApiOperation("清空购物车")
    @DeleteMapping("clean")
    public Result clean()
    {
        log.info("清空购物车");
        shoppingCartService.clean();
        return Result.success();
    }


    @ApiOperation("查看购物车")
    @GetMapping("list")
    public Result list()
        {
            log.info("查看购物车");
            List<ShoppingCart> list = shoppingCartService.list();
            return Result.success(list);
        }

}
